<?php
    $url = new Url(); 
    $forder_upload = "attach_file";  
    $link_avatar = Yii::app()->params["urlImages"]."upload_base.php?forder_upload=".$forder_upload;
    $arr_status = LoadConfig::$status;
?>
 <link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['tiny_url_cp'];?>/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>/js/tinymce_submit.js"></script>
<script type="text/javascript">
    var i =0;
    window.onload = function() {
        var configUploadData = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:0,
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_avatar;?>", 
            file_types: "*.jpg;*.jpeg;*.png;*.gif;*.jar;*.jad;*.doc;*.xls;*.exe;*.ipa;*.apk", 
            file_upload_limit : 20, 
            file_queue_limit : 5, 
            debug : false
        }
        configUpload(configUploadData); 
    }; 
    function uploadResponse(serverData){  
        try {
            $("#txtFileName").val(""); 
            var response = $.parseJSON(serverData); // eval( "(" + serverData + ")" );      
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;
            var str_filename = $("#picture").val() + ';' + filename;
            $("#picture").val(str_filename);
            $("#show_pic").append('<a target="_blank" hef="<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'"alt="'+filename+'" >'+'</a>');
        } catch (e) {

        };
    }
    function ajaxSaveMsg(){
        tinyMCE.triggerSave();
        var check = document.getElementById("all_user").checked;
        if(check==false){
            all_user=0;
        }else{
            all_user=1; 
        }
        var strUrl = "<?php echo $url->createUrl("msgUserTest/ajaxSaveMsg") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                user_to:$("#user_to").val(),
                all_user:all_user,
                title_msg:$("#title_msg").val(),
                description:$("#description").val(),
                picture:$("#picture").val(),
                
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm mới thành công');
                    window.location = '<?php echo $url->createUrl("msgUserTest/index")?>';
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }            
        });
    }
    
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <ul class="form4">
            <li class="clearfix"><label><strong>Gửi cho </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:360px" value="" id="user_to">
                    <input type="checkbox" id="all_user" value="1"/> Tất cả user
                </div>
            </li>
            <li class="clearfix"><label><strong>Tiêu đề tin nhắn </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:500px" value="" id="title_msg"> 
                </div>
            </li>
          
            <li class="clearfix"><label><strong>Nội dung</strong>:</label>
                <div class="filltext">
                    <textarea id="description" name="description"></textarea>
                </div>
            </li>
            <li class="clearfix"><label><strong>File đính kèm </strong>:</label>
                <div class="filltext">
                    <p>
                        <input type="hidden" id="txtFileName" readonly="readonly"/>
                        <input type="text" id="urlFile" style="border:1px solid #DFDFDF; width: 200px;">                            
                        <span id="spanButtonPlaceHolder"></span>
                    </p>
                    <p><i>Định dạng file: *.jpg;*.jpeg;*.png;*.gif(Dung lượng ko được quá 2 MB)</i></p> 
                    <br/>
                    <div class="fieldset flash" id="fsUploadProgress">
                        <span class="legend">File upload</span>
                    </div>

                    <input type="hidden" id="picture" value=""/>
                    <p id="show_pic"></p>
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext">
                    <input id="button_save" onclick="ajaxSaveMsg();" type="button" value=" Thêm mới " class="btn-bigblue"> 
                    &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue"> 
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext" style="color: red;" id="show_error"></div>
            </li>
        </ul>

    </div>
</div>
